<template>
  <!-- 
    点击事件，值的切换
    500渲染
    样式切换
 -->
  <div class="goods-tabs">
    <nav>
      <a
        :class="{ active: localStr === 'detail' }"
        href="javascript:;"
        @click="tabsClick('detail')"
        >商品详情</a
      >
      <a
        :class="{ active: localStr === 'comment' }"
        href="javascript:;"
        @click="tabsClick('comment')"
        >商品评价<span>{{
          goodsInfo.commentCount > 0 ? '(' + goodsInfo.commentCount + '+)' : ''
        }}</span></a
      >
    </nav>
    <!-- 切换内容的地方 -->
    <component :is="'goods-' + localStr"></component>

    <!-- <GoodsDetail v-if="localStr === 'detail'"></GoodsDetail>

    <GoodsComment v-else></GoodsComment> -->
  </div>
</template>
<script>
import { ref, defineAsyncComponent } from 'vue'
// import GoodsDetail from './goods-detail.vue'
// import GoodsComment from './goods-comment.vue'
export default {
  name: 'GoodsTabs',
  props: ['goodsInfo'],
  components: {
    GoodsDetail: defineAsyncComponent(() => import('./goods-detail.vue')),
    GoodsComment: defineAsyncComponent(() => import('./goods-comment.vue'))
  },
  setup () {
    const localStr = ref('detail')
    function tabsClick (str) {
      localStr.value = str
      console.log(str)
    }
    return { tabsClick, localStr }
  }
}
</script>
<style lang="less" scoped>
.goods-tabs {
  min-height: 600px;
  background: #fff;
  nav {
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    a {
      padding: 0 40px;
      font-size: 18px;
      position: relative;
      > span {
        color: @priceColor;
        font-size: 16px;
        margin-left: 10px;
      }
      &:first-child {
        border-right: 1px solid #f5f5f5;
      }
      &.active {
        &::before {
          content: '';
          position: absolute;
          left: 40px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background: @xtxColor;
        }
      }
    }
  }
}
</style>
